/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ThongTinTau.java
 *
 * Created on Oct 25, 2012, 8:38:32 PM
 */
package Panel;
import DAO.TauDAO;
import DAO.TauDAO1;
import OBJECT.Tau;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author ngayngo9x
 */
public class ThongTinTau extends javax.swing.JPanel {
    private int m_maTau;
    private String m_tenTau;
    private String m_tinhTrang;
    private int m_loaiTau;
    private int flagThemSua;
    private static String thanhCong = "Thêm nhân viên thành công";
    private static String thatBai = "Không thể thêm nhân viên";
    /** Creates new form ThongTinTau */
    public ThongTinTau() {
        initComponents();
        flagThemSua = 1;
        this.KhoiTao();
        tenTauTxt.setText("");
        loaiTauCbo.setSelectedIndex(0);
        tinhTrangCbo.setSelectedIndex(0);
        this.m_tenTau = "";
        this.m_loaiTau = 1;
        this.m_tinhTrang = "1";
    }
    
    public ThongTinTau(int maTau, String tenTau, int loaiTau, String tinhTrang) {
        initComponents();
        this.KhoiTao();
        this.m_maTau = maTau;
        this.m_tenTau = tenTau;
        flagThemSua = 2;
        //System.out.print(tenTau);
        tenTauTxt.setText(tenTau);
        this.m_loaiTau = loaiTau;
        System.out.print(loaiTau);
        loaiTauCbo.setSelectedIndex(loaiTau);
        this.m_tinhTrang = tinhTrang;
        tinhTrangCbo.setSelectedIndex(Integer.parseInt(tinhTrang));
    }
    
    
    private void KhoiTao() {
        // Khoi tao combobox : 3 loại tàu ký hiệu lớn, vừa, nhỏ
        loaiTauCbo.removeAllItems();
        loaiTauCbo.addItem("Lớn");
        loaiTauCbo.addItem("Vừa");
        loaiTauCbo.addItem("Nhỏ");
        tinhTrangCbo.removeAllItems();
        tinhTrangCbo.addItem("Tốt");
        tinhTrangCbo.addItem("Hư");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        loaiTauCbo = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        tenTauTxt = new javax.swing.JTextField();
        tinhTrangCbo = new javax.swing.JComboBox();
        nhapLaiBtn = new javax.swing.JButton();
        dongYBtn = new javax.swing.JButton();
        thongBaoLbl = new javax.swing.JLabel();

        jLabel1.setText("Tên Tàu:");

        jLabel2.setText("Tình Trạng:");

        loaiTauCbo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel3.setText("Loại Tàu:");

        tinhTrangCbo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        nhapLaiBtn.setText("Nhập lại");

        dongYBtn.setText("Đồng ý");
        dongYBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dongYBtnActionPerformed(evt);
            }
        });

        thongBaoLbl.setForeground(new java.awt.Color(255, 0, 0));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel2))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addComponent(dongYBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(nhapLaiBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3))
                        .addGap(26, 26, 26)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tenTauTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(loaiTauCbo, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tinhTrangCbo, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(thongBaoLbl, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tenTauTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(loaiTauCbo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addComponent(jLabel2))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tinhTrangCbo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(dongYBtn)
                    .addComponent(nhapLaiBtn))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(thongBaoLbl, javax.swing.GroupLayout.DEFAULT_SIZE, 16, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void Them(String tenTau, int loaiTau, String tinhTrang) {
        int flag = 0;
        TauDAO1 tauDAO = new TauDAO1();
            flag = tauDAO.ThemTau(tenTau, loaiTau, tinhTrang);
            
            if(flag == 1) {
                thongBaoLbl.setText(thanhCong);
            } else {
                thongBaoLbl.setText(thatBai);
            }
            //int tinhTrangCbo = tinhTrangCbo.get
            //int tinhTrangCbo = tinhTrangCbo.ge
    }
    
    private void Sua(String tenTau, int loaiTau, String tinhTrang) {
        int flag = 0;
        TauDAO1 tauDAO = new TauDAO1();
            flag = tauDAO.SuaTau(this.m_maTau, tenTau, loaiTau, tinhTrang);
            if(flag == 1) {
                thongBaoLbl.setText(thanhCong);
            } else {
                thongBaoLbl.setText(thatBai);
            }
            //int tinhTrangCbo = tinhTrangCbo.get
            //int tinhTrangCbo = tinhTrangCbo.get

    }
    
    private void dongYBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dongYBtnActionPerformed
        String tenTau = tenTauTxt.getText();
        //System.out.print(tenTau);
        int loaiTau = loaiTauCbo.getSelectedIndex();
        loaiTau++;
        int temp = tinhTrangCbo.getSelectedIndex() ;
        //temp++;
        String tinhTrang = temp + "";
        System.out.print(loaiTau);
        System.out.print(tinhTrang);
        if(flagThemSua == 1) {
            Them(tenTau, loaiTau, tinhTrang);
        } else {
            tenTau = tenTauTxt.getText();
            loaiTau = loaiTauCbo.getSelectedIndex();
            temp = tinhTrangCbo.getSelectedIndex();
            tinhTrang = temp + "";
            Sua(tenTau, loaiTau, tinhTrang);
        }
        
    }//GEN-LAST:event_dongYBtnActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton dongYBtn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JComboBox loaiTauCbo;
    private javax.swing.JButton nhapLaiBtn;
    private javax.swing.JTextField tenTauTxt;
    private javax.swing.JLabel thongBaoLbl;
    private javax.swing.JComboBox tinhTrangCbo;
    // End of variables declaration//GEN-END:variables
}
